home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.3 Development Libraries / SGI IRIX 6.3 Development Libraries.iso / dist6.3 / gl_dev.idb / usr / share / src / OpenGL / toolkits / libglut / layerutil.c.z / layerutil.c
Encoding:
C/C++ Source or Header  |  1996-12-06  |  4.8 KB  |  161 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1993, 1994, 1995, 1996. */
  3.  
  4. /* This program is freely distributable without licensing fees
  5.    and is provided without guarantee or warrantee expressed or
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. /* Based on XLayerUtil.c: Revision: 1.5 */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include "layerutil.h"
  13.  
  14. static Bool layersRead;
  15. static Atom overlayVisualsAtom;
  16. static OverlayInfo **overlayInfoPerScreen;
  17. static unsigned long *numOverlaysPerScreen;
  18.  
  19. XLayerVisualInfo *
  20. __glutXGetLayerVisualInfo(Display * display, long lvinfo_mask,
  21.   XLayerVisualInfo * lvinfo_template, int *nitems_return)
  22. {
  23.   XVisualInfo *vinfo;
  24.   XLayerVisualInfo *layerInfo;
  25.   Window root;
  26.   Status status;
  27.   Atom actualType;
  28.   unsigned long sizeData, bytesLeft;
  29.   int actualFormat, numVisuals, numScreens, count, i, j;
  30.  
  31.   vinfo = XGetVisualInfo(display, lvinfo_mask & VisualAllMask,
  32.     &lvinfo_template->vinfo, nitems_return);
  33.   if (vinfo == NULL)
  34.     return NULL;
  35.   numVisuals = *nitems_return;
  36.   if (layersRead == False) {
  37.     overlayVisualsAtom = XInternAtom(display,
  38.       "SERVER_OVERLAY_VISUALS", True);
  39.     if (overlayVisualsAtom != None) {
  40.       numScreens = ScreenCount(display);
  41.       overlayInfoPerScreen = (OverlayInfo **)
  42.         malloc(numScreens * sizeof(OverlayInfo *));
  43.       numOverlaysPerScreen = (unsigned long *)
  44.         malloc(numScreens * sizeof(unsigned long));
  45.       if (overlayInfoPerScreen != NULL &&
  46.         numOverlaysPerScreen != NULL) {
  47.         for (i = 0; i < numScreens; i++) {
  48.           root = RootWindow(display, i);
  49.           status = XGetWindowProperty(display, root,
  50.             overlayVisualsAtom, 0L, (long) 10000, False,
  51.             overlayVisualsAtom, &actualType, &actualFormat,
  52.             &sizeData, &bytesLeft,
  53.             (unsigned char **) &overlayInfoPerScreen[i]);
  54.           if (status != Success ||
  55.             actualType != overlayVisualsAtom ||
  56.             actualFormat != 32 || sizeData < 4)
  57.             numOverlaysPerScreen[i] = 0;
  58.           else
  59.             /* four 32-bit quantities per
  60.                SERVER_OVERLAY_VISUALS entry */
  61.             numOverlaysPerScreen[i] = sizeData / 4;
  62.         }
  63.         layersRead = True;
  64.       } else {
  65.         if (overlayInfoPerScreen != NULL)
  66.           free(overlayInfoPerScreen);
  67.         if (numOverlaysPerScreen != NULL)
  68.           free(numOverlaysPerScreen);
  69.       }
  70.     }
  71.   }
  72.   layerInfo = (XLayerVisualInfo *)
  73.     malloc(numVisuals * sizeof(XLayerVisualInfo));
  74.   if (layerInfo == NULL) {
  75.     XFree(vinfo);
  76.     return NULL;
  77.   }
  78.   count = 0;
  79.   for (i = 0; i < numVisuals; i++) {
  80.     XVisualInfo *pVinfo;
  81.     int screen;
  82.     OverlayInfo *overlayInfo;
  83.  
  84.     pVinfo = &vinfo[i];
  85.     screen = pVinfo->screen;
  86.     overlayInfo = NULL;
  87.     if (layersRead) {
  88.       for (j = 0; j < numOverlaysPerScreen[screen]; j++)
  89.         if (pVinfo->visualid ==
  90.           overlayInfoPerScreen[screen][j].overlay_visual) {
  91.           overlayInfo = &overlayInfoPerScreen[screen][j];
  92.           break;
  93.         }
  94.     }
  95.     if (lvinfo_mask & VisualLayerMask)
  96.       if (overlayInfo == NULL) {
  97.         if (lvinfo_template->layer != 0)
  98.           continue;
  99.       } else if (lvinfo_template->layer != overlayInfo->layer)
  100.         continue;
  101.     if (lvinfo_mask & VisualTransparentType)
  102.       if (overlayInfo == NULL) {
  103.         if (lvinfo_template->type != None)
  104.           continue;
  105.       } else if (lvinfo_template->type !=
  106.         overlayInfo->transparent_type)
  107.         continue;
  108.     if (lvinfo_mask & VisualTransparentValue)
  109.       if (overlayInfo == NULL)
  110.         /* non-overlay visuals have no sense of
  111.            TransparentValue */
  112.         continue;
  113.       else if (lvinfo_template->value != overlayInfo->value)
  114.         continue;
  115.     layerInfo[count].vinfo = *pVinfo;
  116.     if (overlayInfo == NULL) {
  117.       layerInfo[count].layer = 0;
  118.       layerInfo[count].type = None;
  119.       layerInfo[count].value = 0;  /* meaningless */
  120.     } else {
  121.       layerInfo[count].layer = overlayInfo->layer;
  122.       layerInfo[count].type = overlayInfo->transparent_type;
  123.       layerInfo[count].value = overlayInfo->value;
  124.     }
  125.     count++;
  126.   }
  127.   XFree(vinfo);
  128.   *nitems_return = count;
  129.   if (count == 0) {
  130.     XFree(layerInfo);
  131.     return NULL;
  132.   } else
  133.     return layerInfo;
  134. }
  135.  
  136. #if 0                   /* unused */
  137. Status
  138. __glutXMatchLayerVisualInfo(Display * display, int screen,
  139.   int depth, int class, int layer,
  140.   XLayerVisualInfo * lvinfo_return)
  141. {
  142.   XLayerVisualInfo *lvinfo;
  143.   XLayerVisualInfo lvinfoTemplate;
  144.   int nitems;
  145.  
  146.   lvinfoTemplate.vinfo.screen = screen;
  147.   lvinfoTemplate.vinfo.depth = depth;
  148.   lvinfoTemplate.vinfo.class = class;
  149.   lvinfoTemplate.layer = layer;
  150.   lvinfo = __glutXGetLayerVisualInfo(display,
  151.     VisualScreenMask | VisualDepthMask |
  152.     VisualClassMask | VisualLayerMask,
  153.     &lvinfoTemplate, &nitems);
  154.   if (lvinfo != NULL && nitems > 0) {
  155.     *lvinfo_return = *lvinfo;
  156.     return 1;
  157.   } else
  158.     return 0;
  159. }
  160. #endif
  161.